import tkinter as tk
from tkinter import filedialog

import wordToPdf
import mergePdf

def get_target_path(root,title):
    # 隐藏主窗口
    root.withdraw()

    folder_path = filedialog.askdirectory(title=title)

    if not folder_path:
        print("没有选择文件夹，程序退出")
        exit()
    return folder_path

def function1(root):
    """功能1的实现"""
    # messagebox.showinfo("功能1", "您选择了功能1")
    root.quit()  # 选择完后关闭窗口
    wordToPdf.convert_files_in_folder(get_target_path(root, '选择word文件夹'))


def function2(root):
    """功能2的实现"""
    # messagebox.showinfo("功能2", "您选择了功能2")
    root.quit()  # 选择完后关闭窗口
    mergePdf.convert(get_target_path(root, '选择PDF文件夹'))


def create_selection_window():
    """创建选择框窗口"""
    # 创建 Tkinter 窗口
    root = tk.Tk()
    root.title("选择功能")

    # 设置窗口大小
    window_width = 300
    window_height = 150

    # 获取屏幕的宽度和高度
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    # 计算窗口的 X, Y 坐标，使窗口居中
    position_top = int((screen_height - window_height) / 2)
    position_left = int((screen_width - window_width) / 2)

    # 设置窗口的大小和位置
    root.geometry(f'{window_width}x{window_height}+{position_left}+{position_top}')

    # 功能1按钮
    button1 = tk.Button(root, text="批量word转换成PDF", width=20, command=lambda: function1(root))
    button1.pack(pady=20)

    # 功能2按钮
    button2 = tk.Button(root, text="合并PDF", width=20, command=lambda: function2(root))
    button2.pack(pady=10)

    # 进入 Tkinter 主循环
    root.mainloop()

if __name__ == "__main__":
    create_selection_window()
